"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025-11-07
"""
from flask import jsonify, request
from app.services.user_service import UserService
from typing import Dict, Any


def create_user():
    data = request.get_json()

    # 简单手动校验（可选）
    if not data or not data.get('username') or not data.get('email'):
        return jsonify({"error": "Missing username or email"}), 400

    user = UserService.create_user(data['username'], data['email'])
    return jsonify(user.to_dict()), 201

def get_user(user_id: int):
    user = UserService.get_user_by_id(user_id)
    if not user:
        return jsonify({"error": "User not found"}), 404
    return jsonify(user.to_dict())

def get_all_users():
    users = UserService.get_all_users()
    return jsonify([user.to_dict() for user in users])
